package com.hontek.demo.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Random;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.struts2.ServletActionContext;

import com.hontek.demo.service.imp.UserServiceImp;
import com.hontek.demo.vo.SysUser;
import com.opensymphony.xwork2.ActionSupport;

public class DemoAction extends ActionSupport{
	private String username;
	private String pwd;
	private UserServiceImp userservice;
	private int rows;
	private int page;
	@Override
	public String execute() throws Exception {
//		System.out.println("username=="+username);
//		System.out.println("pwd==="+pwd);
		
		
		
		SysUser user = new SysUser();
		user.setBrithday("2013-08-30");
		user.setEmail("lbbb@163.comm");
		user.setPassword(pwd);
		user.setUserId(new Random().nextInt(100));
		user.setUserName(username);
		userservice.insertUser(user);
		
		return SUCCESS;
	}
	
	public String showlist() throws IOException{
		System.out.println("rows============"+rows);
		System.out.println("page============"+page);
		
		
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding ( "utf-8" );
		PrintWriter out = response.getWriter();
		List userlist = userservice.userList();
		String rest_json = JSONArray.fromObject(userlist).toString();
		
		String str = "{\"total\":28,\"rows\":"+rest_json+"}";
		
		out.println(str);
		out.close();
		return null;
	}
	
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public UserServiceImp getUserservice() {
		return userservice;
	}

	public void setUserservice(UserServiceImp userservice) {
		this.userservice = userservice;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}
	
}
